/*! \file Singleton.h
 *	\brief <write description for Singleton.h>
 *
 *	created:	2010/02/14
 *	created:	14:2:2010   12:46
 *	filename: 	C:\src\gag-engine\libs\utils\Singleton.h
 *	file path:	C:\src\gag-engine\libs\utils
 *	file base:	Singleton
 *	file ext:	h
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */

#ifndef _UTILS_SINGLETON_H_
#define _UTILS_SINGLETON_H_

#pragma once

#include <core/SmartPtr.h>

namespace tt{
namespace utils{

template<typename Instance>
class Singleton
{
protected:
	Singleton();

public:
	static void CreateInstance();
	static void CreateInstance(Instance*);
	static void DestroyInstance();

	static Instance& GetInstance();
};

#define TT_SINGLETON_INSTANCE(Class) \
	namespace tt{ \
	namespace utils{ \
	namespace impl{ \
		template<> \
		ScopedPtr<Class> SingletonHolder<Class>::s_instance; \
	} \
	} \
	} 

} //namespace utils

#define TT_SINGLETON_GET_FUNCTION(Class, FunctionName) \
	inline \
	Class& FunctionName() { return Class::GetInstance(); }

#define TT_SINGLETON_DEFAULT_INSTANCE(Class, DefaultInstanceClass) \
	namespace tt { \
	namespace utils { \
	namespace impl{ \
	template<> \
	class SingletonDefault<Class> \
	{ \
	public: \
		Class* Create() { return new DefaultInstanceClass(); }	\
	}; \
	} \
	} \
	} 

} //namespace tt
#include "Singleton.inl"

#endif //_UTILS_SINGLETON_H_